﻿using B.S.Ingredients.APIRead.Application.Command.Over;
using B.S.Ingredients.Domain;
using B.S.Ingredients.ErrorCode;
using B.S.Ingredients.Infartructrue.Enit;
using B.S.Ingredients.Infartructrue.Interfaces;
using MediatR;

namespace B.S.Ingredients.APIRead.Application.CommandHandler.OverHandler
{
    public class OverTimeQueryCommandHandler : IRequestHandler<OverTimeQueryCommand, APIResult<OvertimeClass>>
    {
        public OverTimeQueryCommandHandler(IBaseRepository<OvertimeClass> overtimeRepository)
        {
            OvertimeRepository = overtimeRepository;
        }

        public IBaseRepository<OvertimeClass> OvertimeRepository { get; }

        public async Task<APIResult<OvertimeClass>> Handle(OverTimeQueryCommand request, CancellationToken cancellationToken)
        {
            var path = OvertimeRepository.GetAll().FirstOrDefault(a => a.Productuins == request.Productuins);
            return new APIResult<OvertimeClass> 
            {
                Code = ResultCode.success,
                Mag = "",
                Data = path
            };
        }
    }
}
